//
// Created by 周智超 on 2020/6/28.
//

#include "tree.h"
#include <iostream>
#include "gtest/gtest.h"


TEST(exercise, count_linkleaf)
{
    BTNode *root;
    int flag;
    root = initBT(5, initBT(3, NULL, NULL), initBT(8, initBT(2, NULL, NULL), NULL));
    flag = 0;
    countBT(root, flag);
    ASSERT_EQ(4, flag);
    flag = 0;
    countBTLeaf(root, flag);
    ASSERT_EQ(2, flag);
    BTNode *head = NULL;
    BTNode *tail = NULL;
    BTNode *prev = NULL;
    linkLeaf(root, head, tail, prev);
    ASSERT_EQ(head->data, 3);
    ASSERT_EQ(tail->data, 2);
    head = head->rchild;
    ASSERT_EQ(head->data, 2);
    head = head->rchild;
    ASSERT_TRUE(head == NULL);
    root = initBT(5, initBT(3, NULL, NULL), initBT(8, initBT(2, NULL, NULL), NULL));
    linkParent(root, NULL);
    printBatch(root);

}

TEST(exercise, transferFull)
{
    int a[] = {1,2,4,5,3,6,7};
    transfer2PostForFullBt(a, 7);
    printNormalArr(a, 7);
}

TEST(exercise, x)
{
    BTNode* root = initBT(5, initBT(3, initBT(2, NULL, NULL), initBT(4, NULL, NULL)), NULL);
    int flag = levelOfBT(root, 2);
    ASSERT_EQ(3, flag);
    flag = levelOfBT(root, 7);
    ASSERT_EQ(-1, flag);
    doubleIter(root);
}


TEST(exercise, allPath)
{
    BTNode *root = initBT(8,
            initBT(7, initBT(9, initBT(4, NULL, NULL), initBT(13, NULL, NULL)), NULL), initBT(20, NULL, NULL));
    allPath(root);
}

int main(int argc,char *argv[])
{
    testing::InitGoogleTest(&argc, argv);//将命令行参数传递给gtest
    return RUN_ALL_TESTS();   //RUN_ALL_TESTS()运行所有测试案例
}
